﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using LINQPad.OpenAccess.Helpers;

namespace LINQPad.OpenAccess.Metadata.Reflection
{
    /// <summary>
    /// EntitySet - Info
    /// </summary>
    public class EntitySetInfo
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="EntitySetInfo" /> class.
        /// </summary>
        /// <param name="contextType">Type of the context.</param>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="entitySetProperty">The entity set property.</param>
        /// <param name="name">The name.</param>
        public EntitySetInfo( Type contextType, Type entityType, PropertyInfo entitySetProperty, string name = null )
        {
            Guard.ArgumentNotNull( contextType, "contextType" );
            Guard.ArgumentNotNull( entityType, "entityType" );
            Guard.ArgumentNotNull( entitySetProperty, "entitySetProperty" );

            this.ContextType = contextType;
            this.EntityType = entityType;
            this.EntitySetProperty = entitySetProperty;
            this.Name = name ?? entitySetProperty.Name ?? String.Empty;
        }

        /// <summary>
        /// Gets the type of the context.
        /// </summary>
        /// <value>
        /// The type of the context.
        /// </value>
        public Type ContextType { get; private set; }
        /// <summary>
        /// Gets the type of the entity.
        /// </summary>
        /// <value>
        /// The type of the entity.
        /// </value>
        public Type EntityType { get; private set; }
        /// <summary>
        /// Gets the type of the entity set.
        /// </summary>
        /// <value>
        /// The type of the entity set.
        /// </value>
        public Type EntitySetType
        {
            get
            {
                return this.EntitySetProperty.PropertyType;
            }
        }
        /// <summary>
        /// Gets the entity set property.
        /// </summary>
        /// <value>
        /// The entity set property.
        /// </value>
        public PropertyInfo EntitySetProperty { get; private set; }
        /// <summary>
        /// Gets the name of the entity set.
        /// </summary>
        /// <value>
        /// The name.
        /// </value>
        public string Name { get; private set; }
    }
}
